//
//  HRSignHeadView.m
//  Hear
//
//  Created by mac on 2018/3/5.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "HRSignHeadView.h"
#import "UIButton+SSEdgeInsets.h"
@interface HRSignHeadView ()
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UIButton *goldButton;
@property (nonatomic,strong)UIButton *showSignOfgoldButton;
@property (nonatomic,strong)UIButton *signButton;

@end
@implementation HRSignHeadView

-(void)setSignInModel:(HRSignInModel *)signInModel{
    _signInModel = signInModel;
    [self.showSignOfgoldButton setTitle:[NSString stringWithFormat:@"签到 +%@",signInModel.signInfoModel.coins] forState:0];
    
    if ([signInModel.signInfoModel.completion intValue]){
        [self.showSignOfgoldButton setBackgroundImage:[UIImage imageNamed:@"签到灰色"] forState:0];
        [self.signButton setImage:[UIImage imageNamed:@"已签到"] forState:0];
    }
    
    [self.goldButton setTitle:[NSString stringWithFormat:@"我的乐币%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"Balance"]] forState:0];
    
    
    [self.goldButton setImagePositionWithType:SSImagePositionTypeRight spacing:5];
}



-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, frame.size.height-60)];
        self.bgImageView.image = [UIImage imageNamed:@"bg"];
        [self addSubview:self.bgImageView];
        self.bgImageView.userInteractionEnabled = YES;
        
        UIButton *signButton = [[UIButton alloc] initWithFrame:CGRectMake((self.bgImageView.width-100)/2, 100, 100, 100)];
        [signButton setImage:[UIImage imageNamed:@"未签到"] forState:0];
        [self.bgImageView addSubview:(self.signButton=signButton)];
        
        self.goldButton = [[UIButton alloc] initWithFrame:CGRectMake((self.bgImageView.width-120)/2, signButton.bottom+30, 120, 20)];
        self.goldButton.titleLabel.font = CustomUIFont(13);
        [self.goldButton setImage:[UIImage imageNamed:@"乐币"] forState:0];
        [self.bgImageView addSubview:self.goldButton];
        
        self.showSignOfgoldButton = [[UIButton alloc] initWithFrame:CGRectMake(self.goldButton.left, self.goldButton.bottom+20, 120, 45)];
        [self.showSignOfgoldButton setBackgroundImage:[UIImage imageNamed:@"签到"] forState:0];
        [self.showSignOfgoldButton setTitle:@"签到 +1" forState:0];
        self.showSignOfgoldButton.titleLabel.font = CustomUIFont(13);
        [self.showSignOfgoldButton setImage:[UIImage imageNamed:@"乐币"] forState:0];
        [self.showSignOfgoldButton setImagePositionWithType:SSImagePositionTypeRight spacing:5];
        [self.bgImageView addSubview:self.showSignOfgoldButton];
        [self.showSignOfgoldButton addTarget:self action:@selector(signClick:) forControlEvents:UIControlEventTouchUpInside];
        
        
        UILabel *remendLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, self.bgImageView.bottom+20, 70, 20)];
        remendLabel.text = @"赚取乐币";
        remendLabel.font = CustomUIFont(14);
        remendLabel.textColor = FirstTextColor;
        [self addSubview:remendLabel];
        
        
    }
    return self;
}

- (void)signClick:(UIButton *)button{
    if ([_signInModel.signInfoModel.completion intValue]) return;
    [self.showSignOfgoldButton setBackgroundImage:[UIImage imageNamed:@"签到灰色"] forState:0];
    [self.signButton setImage:[UIImage imageNamed:@"已签到"] forState:0];
    if (self.signBlock){
        self.signBlock();
    }

}
@end
